package com.lr.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JSONUtil {
    private static ObjectMapper jacksonMapper = new ObjectMapper();

    //把对象变json
    public static String ObjectToJson(Object o) {
        try {
            return jacksonMapper.writeValueAsString(o);
        } catch (JsonProcessingException e) {
        }
        return null;
    }
    //把json变对象
    public static <T> T jsonToObject(String json, Class<T> clazz) {
        try {
            return jacksonMapper.readValue(json, clazz);
        } catch (JsonProcessingException e) {
        }
        return null;
    }
}
